﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using TurtleLib.ComputerCraft;

namespace TurtleLib.Simulation
{
  public class ComputerUx : Screen, ISubscriber<ComputerCraft.Computer>
  {
    public ComputerUx(DragablePanel parent) : base(parent)
    {
      parent.BackColor = Color.WhiteSmoke;
    }

    public void SubscribeTo(ComputerCraft.Computer host)
    {
      var caccess = new ComputerCraft.Computer.ComputerAccess(host);
      SetTitle(host.GetType().Name);

      var peripheralAccess = new ComputerCraft.PeripheralUtility.PeripheralUtilityAccess(caccess.PeripheralUtility);
      peripheralAccess.WorldLocationRequestCallback = () => _parent.World.GetLocation(host);
      peripheralAccess.WorldFaceRequestCallback = () => _parent.World.GetFace(host);
      peripheralAccess.WorldObjectLookupCallback = pos => _parent.World.GetObject(pos);

      SubscribeToStatusUpdates(host);
      base.SubscribeTo(caccess.Term);
    }
  }
}
